package com.winit.openapi.tms.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;
import com.winit.openapi.constants.ErrorCode;
import com.winit.openapi.controller.BaseController;
import com.winit.openapi.exception.ApiException;
import com.winit.openapi.model.RequestMsg;
import com.winit.openapi.model.ResponseMsg;
import com.winit.tms.spi.rule.SendWarehouseRuleService;
import com.winit.tms.spi.rule.command.SendWarehouseIntervalSearchCommand;
import com.winit.tms.spi.rule.vo.SendWarehouseIntervalVo;

/**
 * 
 * 送仓数据
 * @version 
 * <pre>
 * Author	Version		Date		Changes
 * jianhua.huang 	1.0  		2015-12-3 	Created
 *
 * </pre>
 * @since 1.
 */

@Controller
@RequestMapping(value = "/tms/sendWarehouseRule")
public class SendWarehouseRuleController extends BaseController {

    @Resource
    private SendWarehouseRuleService sendWarehouseRuleService;

    /**
     * 查询送仓时间
     * 
     * @param requestMsg
     * @param responseMsg
     * @return
     */
    @RequestMapping(value = "/API")
    public String querySendWarehouse(@ModelAttribute RequestMsg requestMsg, @ModelAttribute ResponseMsg responseMsg) {

        Object obj = requestMsg.getData();
        if (obj instanceof JSONObject) {
            JSONObject json = (JSONObject) obj;

           SendWarehouseIntervalSearchCommand command = new SendWarehouseIntervalSearchCommand();
            command.setDeliveryDate(json.getDate("deliveryDate"));
            command.setDestinationWarehouseCode(json.getString("deliveryWarehouseCode"));
            List<SendWarehouseIntervalVo> list = sendWarehouseRuleService.querySendWarehouseInterval(command);

            Map<Object, Object> data = new HashMap<Object, Object>();
            data.put("sendWarehouseIntervalList", list);
            responseMsg.setData(data);
        } else {
            throw new ApiException(ErrorCode.FIELD_TYPE_ERROR, "data");
        }
        return SUCCESS;
    }
}
